Method and Apparatus for Identifying and Eliminating Duplicate Data Blocks and Sharing Data Blocks in a Storage System

ABSTRACT

A method for sharing data blocks in a hierarchical file system in a storage server includes allocating a plurality of data blocks in the file system, and sharing data blocks in the file system, without using a persistent point-in-time image, to avoid duplication of data blocks. A method for identifying data blocks that can be shared includes computing a fingerprint for each of multiple data blocks to be written to a storage facility and storing the fingerprint with information identifying the data block in an entry in a set of metadata. The set of metadata is used to identify data blocks which are duplicates.

FIELD OF THE INVENTION

At least one embodiment of the present invention pertains to datastorage systems, and more particularly, to a technique for identifyingand eliminating duplicate data blocks and for sharing data blocksmanaged by a file system.

BACKGROUND

In a data storage system it is desirable to use storage space asefficiently as possible, to avoid wasting storage space. One type ofsystem in which this concern can be particularly important is a storageserver, such as a file server. File servers and other types of storageservers often are used to maintain extremely large quantities of data.In such systems, efficiency of storage space utilization is critical.

Files maintained by a file server generally are made up of individualblocks of data. A common block size is four kilobytes. In a large filesystem, it is common to find duplicate occurrences of individual blocksof data. Duplication of data blocks may occur when, for example, two ormore files have some data in common or where a given set of data occursat multiple places within a given file has. Duplication of data blocksresults in inefficient use of storage space.

A technique which has been used to address this problem in the prior artis referred to as “file folding”. The basic principle of file folding isto allow new data of a file in the active file system to share a diskblock with the old data of the file in a persistent image if the newdata are identical to the old data. By using file folding, ideally onlyone occurrence of each unique data block will exist in a file system.This technique has been implemented in file servers, known as Filers,made by Network Appliance, Inc., of Sunnyvale, Calif. Specifically,Network Appliance Filers are capable of acquiring a Snapshot™ of aspecified set of data. A “Snapshot” is a persistent, read-only image ofthe storage system, and more particularly, of the active file system, ata particular instant in time. If a block within a file that has been“Snapshotted” is modified after the Snapshot, rather than creatinganother complete (modified) copy of the file in the active file system,the Filer only creates the modified block for that file in the activefile system; for each unmodified block, the Filer simply gives the filea pointer to the corresponding block in the Snapshot. In this way, theunmodified blocks in the Snapshot become shared between the Snapshot andthe active file system. This technique is described in greater detail inU.S. Patent Application Publication no. 2003/0182317, entitled, “FileFolding Technique,” filed on Mar. 22, 2002 by A. Kahn et al., andassigned to the assignee of the present application.

File folding does help to more efficiently use storage space. However,it is desirable to reduce data duplication in an active file systemwithout having to rely upon a persistent point-in-time image (e.g., aSnapshot). It is also desirable to reduce data duplication regardless ofthe location of the data in the file system.

Another prior art approach to avoiding duplication of data in a storagesystem involves computing a hash value for every file that is stored.For example, in one known prior art system, which does not use atraditional (hierarchical) file system approach, a storage server isused to store data on behalf of an application server or other client.When the application server wants the storage server to store aparticular file, the application server computes a hash value for thefile and sends the storage server a write request containing the fileand the hash value.

The storage server uses hash values of files to help reduce dataduplication. More specifically, the storage server maintains a databasecontaining a mapping of all of the stored files to their respective hashvalues. When the storage server receives a write request with a hashvalue, it searches for a match of that hash value in its database. If nomatch is found, the storage server concludes that it does not have acopy of that file already stored, in which case the storage serverrequests the file from the application server. If a match of the hashvalue is found, however, the storage server concludes that it alreadyhas a copy of that file stored and, therefore, does not have to requestthe file from the application server.

This method of using hash values employs a proprietary set of protocolsand semantics, which are very different from those used in a traditional(hierarchical) file system. Further, the need to compute a hash valuefor every read or write and for every data block adversely affectsperformance, particularly during reads. In addition, every time a fileis modified, the file has to be stored as a new file with a new hashvalue associated with it. Moreover, this approach involves complicatedcleanup issues with regard to determining when particular blocks can befreed.

SUMMARY OF THE INVENTION

The present invention includes a method and apparatus for sharing datablocks in a hierarchical file system in a storage server. In at leastone embodiment, the method includes allocating a plurality of datablocks in the hierarchical file system, and sharing data blocks in thehierarchical file system, without using a persistent point-in-timeimage, to avoid duplication of data blocks.

Another aspect of the invention is a method and an apparatus foridentifying data blocks that can be shared. In at least one embodiment,the method includes computing a fingerprint for each of multiple datablocks to be written to a storage facility and storing the fingerprintwith information identifying the data block in an entry in a set ofmetadata. The method further includes using the set of metadata toidentify data blocks which are duplicates.

Other aspects of the invention will be apparent from the accompanyingfigures and from the detailed description which follows.

BRIEF DESCRIPTION OF THE DRAWINGS

One or more embodiments of the present invention are illustrated by wayof example and not limitation in the figures of the accompanyingdrawings, in which like references indicate similar elements and inwhich:

FIG. 1 illustrates an example of a network environment which includes afile server;

FIG. 2 is a high-level block diagram showing an example of thearchitecture of a file server;

FIG. 3 shows an example of the architecture of the operating system of afile server;

FIG. 4 is a flow diagram showing an overall process of a technique foridentifying and eliminating duplicate data blocks and sharing datablocks;

FIGS. 5 through 7 illustrate how the technique of FIG. 4 can be appliedwith respect to two files;

FIG. 8 illustrates elements of a de-duplication module;

FIG. 9 is a state diagram showing the states which a data block canhave;

FIG. 10 is a flow diagram showing a process performed by thede-duplication module when a block is written to disk;

FIG. 11 illustrates a process of eliminating duplicate data blocks;

FIG. 12 illustrates a process of sorting a fingerprints database; and

FIG. 13 is a flow diagram showing the process of freeing a data block.

DETAILED DESCRIPTION

A method and apparatus for identifying and eliminating duplicate datablocks and for sharing data blocks in a hierarchical file system aredescribed. As explained in greater detail below, the techniqueintroduced herein allows sharing of data blocks in a hierarchical filesystem of a storage server to avoid duplication of data blocks anywherein the file system, without using any persistent point-in-time image(PPI), such as a Snapshot. The technique also does not require anyclient-side behavioral/design changes or appreciably impact read/writeperformance in a negative way.

In certain embodiments of the invention, the sharing of data blocksinvolves maintaining a reference count file that contains, for each datablock in the file system, a reference count indicating the number ofreferences to the data block. Shared data blocks are blocks which arethe target of two or more references. Data blocks that can be shared areidentified by computing a fingerprint for each data block to be writtento a storage facility and storing the fingerprint with informationidentifying the data block in an entry in a metadata file, as the datablock is being written to the storage facility. A “fingerprint”, as theterm is used herein, is any information derived from the content of adata block, that might uniquely identify the data block. The entries inthe metadata file are then sorted by fingerprint, and the sortedmetadata file is used to identify data blocks which are duplicates.Duplicate data blocks are freed for reuse, and their remainingcounterparts which are not freed are shared to the extent possible.

One example of a system in which this technique can be implemented is afile server system. FIG. 1 shows an example of a network environment inwhich such a system can be employed. In FIG. 1, a file server 2 iscoupled locally to a storage subsystem 4 which includes multiple massstorage devices, and to a set of clients 1 through a network 3, such asa local area network (LAN). Each of the clients 1 may be, for example, aconventional personal computer (PC), workstation, or the like. Thestorage subsystem 4 is managed by the file server 2. The file server 2receives and responds to various read and write requests from theclients 1, directed to data stored in or to be stored in the storagesubsystem 4. The mass storage devices in the storage subsystem 4 may be,for example, conventional magnetic disks, optical disks such as CD-ROMor DVD based storage, magneto-optical (MO) storage, or any other type ofnon-volatile storage devices suitable for storing large quantities ofdata. The storage devices in storage subsystem 4 can be organized as aRedundant Array of Inexpensive Disks (RAID), in which case the fileserver 2 accesses the storage subsystem 4 using one or more well-knownRAID protocols.

The file server 2 may be a file server designed for use in a networkattached storage (NAS) mode (otherwise referred to as a “filer”), as ishenceforth assumed in this description. The technique introduced hereincan be implemented in the file server 2, or in other devices, asdescribed below. The technique can also be adapted for use in othertypes of storage systems, however, such as storage servers which provideclients with block-level access to stored data, or processing systemsother than storage servers.

FIG. 2 is a block diagram showing an example of the architecture of thefile server 2 at a high level. Certain standard and well-knowncomponents which are not germane to the present invention are not shown.The file server 2 includes one or more processors 21 and memory 22coupled to a bus system 23. The bus system 23 shown in FIG. 2 is anabstraction that represents any one or more separate physical busesand/or point-to-point connections, connected by appropriate bridges,adapters and/or controllers. The bus system 23, therefore, may include,for example, a system bus, a Peripheral Component Interconnect (PCI)bus, a HyperTransport or industry standard architecture (ISA) bus, asmall computer system interface (SCSI) bus, a universal serial bus(USB), or an Institute of Electrical and Electronics Engineers (IEEE)standard 1394 bus (sometimes referred to as “Firewire”).

The processors 21 are the central processing units (CPUs) of the fileserver 2 and, thus, control its overall operation. In certainembodiments, the processors 21 accomplish this by executing softwarestored in memory 22. A processor 21 may be, or may include, one or moreprogrammable general-purpose or special-purpose microprocessors, digitalsignal processors (DSPs), programmable controllers, application specificintegrated circuits (ASICs), programmable logic devices (PLDs), or thelike, or a combination of such devices.

Memory 22 includes the main memory of the file server 2. Memory 22represents any form of random access memory (RAM), read-only memory(ROM), flash memory, or the like, or a combination of such devices.Memory 22 stores (among other things) the storage server's operatingsystem 24, which can implement the technique introduced herein.

Also connected to the processors 21 through the bus system 23 are one ormore internal mass storage devices 25, a storage adapter 26 and anetwork adapter 27. Internal mass storage devices 25 may be or includeany conventional medium for storing large volumes of data in anon-volatile manner, such as one or more magnetic or optical baseddisks. The storage adapter 26 allows the file server 2 to access thestorage subsystem 4 and may be, for example, a Fibre Channel adapter ora SCSI adapter. The network adapter 27 provides the file server 2 withthe ability to communicate with remote devices, such as the clients 1,over a network and may be, for example, an Ethernet adapter, a FibreChannel adapter, or the like.

FIG. 3 shows an example of the architecture of the operating system 24of the file server 2. As shown, the operating system 24 includes severalsoftware modules, or “layers”. These layers include a file system 31.The file system 31 is application-layer software which imposes ahierarchical structure on the data stored in the storage subsystem 4(i.e., a hierarchy of files and directories) and which servicesread/write requests from clients 1. Logically “under” the file system31, the operating system 24 also includes a protocol layer 32 and anassociated network access layer 33, to allow the file server 2 tocommunicate over the network 3 (e.g., with clients 1). The protocol 32layer implements one or more of various higher-level network protocols,such as Network File System (NFS), Common Internet File System (CIFS),Hypertext Transfer Protocol (HTTP) and/or Transmission ControlProtocol/Internet Protocol (TCP/IP), and serves to translate read/writerequests from clients into a format understandable by the file system31. The network access layer 33 includes a driver or drivers toimplement one or more lower-level protocols to communicate over thenetwork, such as Ethernet, Fibre Channel or iSCSI.

Also logically under the file system 31, the operating system 24includes a storage access layer 34 and an associated storage driverlayer 35, to allow the file server 2 to communicate with the storagesubsystem 4. The storage access layer 34 implements a higher-level diskstorage protocol, such as RAID, while the storage driver layer 35implements a lower-level storage device access protocol, such as FibreChannel Protocol (FCP) or small computer system interface (SCSI). Alsoshown in FIG. 3 is the path 37 of data flow, through the operatingsystem 24, associated with a read or write operation.

The operating system 24 also includes a user interface module 36 and ade-duplication module 39 logically on top of the file system 31. Theuser interface module may implement a command line interface and/or agraphical user interface, which may be accessed by a networkadministrator from an attached administrative console or through thenetwork 3. The de-duplication module 39 is an application layer whichidentifies and eliminates duplicate data blocks (“de-duplication”) andtriggers data block sharing in accordance with the technique introducedherein.

The operating system 24 also includes, or has access to, three databasesthat are used to implement the sharing technique, namely, a referencecount file 41, an Active map 42 and a fingerprints database 43. Thereference count file 41 contains an entry for each data block maintainedby the file server 2, wherein each entry includes a value, REFCOUNT,indicating the number of references to that data block. For example, adata block which is shared by two files would have a REFCOUNT value of2. A data block can be shared by more than two files (or otherentities), in which case the REFCOUNT value would reflect thisaccordingly. A data block which is allocated but not shared would have aREFCOUNT value of 1. A data block which is not yet allocated would havea REFCOUNT value of 0. In certain embodiments of the invention, theREFCOUNT value for each data block is a two-byte binary value, whichallows each data block to be the target of up to 2¹⁶−1 references.

The Active map 42 is a bitmap of all data blocks managed by the fileserver 2, i.e., one bit per data block. The bit for a given data blockis set in the Active map 42 if the data block is allocated and clearedif the data block is free to be used. The Active map 42 is used duringallocation of blocks to determine whether a block is free or not. TheActive map 42 helps to improve performance by avoiding the need to readthe reference count file 41 to identify free blocks; the reference countfile 41 is much larger (and therefore takes longer to read) than theActive map 42. In an alternative embodiment, however, the Active map 42and the reference count file 41 could be combined into a single file toidentify each free block as well as to indicate the number of referencesto the data block.

The fingerprints database 43 is used by the de-duplication module 39 tostore a fingerprint for each data block that is written to the storagesubsystem 4. In this context, a “fingerprint” may be a checksum, forexample. The fingerprints are used in a process for efficientlyidentifying duplicate data blocks, i.e., to identify data blocks thatcan be shared. This process is described below in detail.

FIG. 4 shows the overall process of the technique introduced herein at ahigh-level, according to certain embodiments of the invention. The firstphase 401 is identifying duplicate data blocks. Once the duplicate datablocks are identified, the duplicates are eliminated at 402 so as toleave only one instance of each unique data block. This phase 402includes sharing the remaining instance of each data block that wasduplicated and freeing the (no longer used) duplicate data block(s).Phase 402 also involves updating the reference count file 41, Active map42 and fingerprints database 43. This whole process may be triggeredautomatically at predetermined intervals or at predetermined times, orit may be triggered manually or in response to pre-specified events(such as deletion of a file) or in response to a pre-specified policy(such as a given number of new blocks having been collected).

The sharing technique will now be further described with reference toFIGS. 5, 6 and 7, according to certain embodiments of the invention.Assume for purposes of explanation that the active file system of a fileserver maintains two simple files, named Foo and Bar, shown in FIG. 5.File Foo contains two data blocks, and file Bar contains two datablocks. Each data block is identified in the file system by (among otherthings) its volume block number (VBN). A VBN identifies the logicalblock where the data is stored (since RAID aggregates multiple physicaldrives as one logical drive), as opposed to a physical block. A VBNshould be distinguished from a disk block number (DBN) which identifiesthe physical block number within a disk in which the block is stored, ora file block number (FBN) which identifies the logical position of thedata within a file. The two blocks of file Foo have VBN values of 1 and2. VBN 1 contains the data, “A”, while VBN 2 contains the data, “B”. Thetwo blocks of file Bar have VBN values of 3 and 4. VBN 3 contains thedata, “C”, while VBN 4 contains the data, “D”.

For each VBN maintained by the file system, the reference count file 41includes a value, REFCOUNT, indicating the number of references to thatVBN. In the example of FIG. 5, for VBNs [1,2,3,4] the REFCOUNT valuesare [1,1,1,1], respectively, indicating that each VBN is the target ofone reference.

Refer now to FIG. 6, which is a variation of the example of FIG. 5, inwhich VBNs 3 and 4 of file Bar have the same data (“A”) as VBN 1 of fileFoo. That is, VBNs 3 are 4 are duplicates of VBN 1 and of each other.Initially, when a data block is allocated by the file system, itsREFCOUNT value in the reference count file 41 is set equal to 1.Accordingly, before duplicate data blocks are identified in the exampleof FIG. 6, the REFCOUNT values for the example of FIG. 6 are the same asin FIG. 5, i.e., [1,1,1,1], as shown.

In contrast, FIG. 7 shows what the example of FIG. 6 would look likeafter duplicate data blocks has been identified and sharing isimplemented. Sharing involves giving, to each entity which owns ashareable data block, a pointer to that data block. Accordingly, in theexample of FIG. 7 this involves giving file Bar two pointers to VBN 1(file Foo already had a pointer to VBN 1). The process also involveseliminating the duplicate data blocks, VBNs 3 and 4, and freeing themfor reuse. Once this process is completed, the REFCOUNT values for VBNs[1,2,3,4] are adjusted to be [3,1,0,0], respectively, to reflect thefact that VBNs 3 and 4 have been freed and VBN 1 now has threereferences to it (i.e., VBN 1 is shared).

The reference count file 41 is continually updated to reflect eventsthat affect these blocks. For example, if file Foo is now deleted, theREFCOUNT values for VBNs [1,2,3,4] would be adjusted to be [2,0,0,0],respectively, reflecting that VBN 2 has been freed in addition to VBNs 3and 4. Note that VBN 1 has not been freed (i.e., its REFCOUNT value isnot zero), since VBN 1 is still in use by file Bar; instead the REFCOUNTvalue for VBN 1 has been decremented from 3 to 2. If file Bar is nowdeleted, the REFCOUNT values for VBNs [1,2,3,4] would be adjusted to be[0,0,0,0], respectively.

The approach just described assumes that the file system adheres to thecopy-on-write principle; that is, anytime a data block is modified, itis written to a different VBN, rather than modifying the data in place.Referring back to the example of FIG. 7, therefore, assume that a writerequest from a client causes the data “A” in file Bar to be changed to“F”. In this case, VBN 1, which contains the data “A”, is not modified.However, since the new data, “F”, is written to a new logical andphysical block, the REFCOUNT value for VBN 1 must still be updated.Hence, the REFCOUNT value for VBN 1 in this case would be decremented byone. In addition, the REFCOUNT value for whichever VBN is allocated tostore the new data, “F”, would be incremented by one.

It is possible to implement this technique even in a file system whichdoes not impose copy-on-write in all instances. For example, thetechnique can be employed by requiring copy-on-write only when theREFCOUNT value for given data block is greater than one.

To avoid data inconsistencies, when a file which contains one or moreshared blocks is modified, its REFCOUNT values and block pointers areupdated in a single atomic transaction. This updating may be done, forexample, during a “consistency point”, i.e., when a set of accumulatedwrite transactions are committed from temporary storage to persistentstorage.

It is possible for data in the reference count file 41 to becomecorrupted, for any of various reasons. Therefore, it is prudent to havesome way of ensuring consistency between the reference count file 41 andthe actual state of the file system. One way this can be accomplished isscanned the entire active file system for consistency with the referencecount file 41 before boot-up of the file system. This can includecreating a separate, temporary reference count file in main memory ofthe file server 2, scanning all data blocks in the file system toidentify shared data blocks, and updating the temporary reference countfile to reflect any shared data blocks. The temporary reference countfile is then compared to the regular (persistent, on-disk) referencecount file 41 to determine whether they match. If they do not match, aninconsistency is identified, and appropriate corrective action is taken.

In addition, it may be desirable to allow this type of consistency checkto be run while the file system is in operation. This can be done bycreating the temporary reference count file on disk, so as not toconsume main memory in the file server 2. In that case, however, if theuser modifies a particular block while the consistency check is running,it is necessary to update both the temporary and the persistentreference count files.

Various other optimizations can be added to the above describedtechnique. For example, a SHARED flag can be provided for each file inthe file system, to indicate whether the file contains any sharedblocks. The SHARED flag can be stored in a convenient location, such asin the file's inode (a container of metadata about the file, used by thefile system), to allow fast determination of whether it is necessary toread the reference count file 41 when modifying a block. This avoidsunnecessarily having to read the (large) reference count file 41 whenthe file includes no shared blocks. Similarly, another flag can beimplemented for each volume in the storage system, to indicate whetherthe volume is allowed to implement block sharing. The benefit, as in theprevious example, is avoiding the need to read the reference count file41 in all cases.

Further, one or more counters can be implemented in the file system totrack the total number of shared blocks. These counters can be used toprovide an output to a user (e.g., a storage network administrator)indicating the amount of disk space being saved as a result of blocksharing.

There are many possible advantageous uses of the above-describedtechnique. For example, this technique allows any individual file to becopied by simply copying its block pointers and incrementing theREFCOUNT values of all of its data blocks by one, without actuallycreating copies of the data blocks. In this way, it is possible tocreate a single-file PPI, i.e., a persistent point-in-time image of aparticular file. In the event the file is modified after the PPI istaken, it is possible to revert the particular file back to the PPI aslong as the PPI remains available.

Another advantage of the above-described technique is “file cloning”functionality. By copying the block pointers from one file to anotherfile, it is possible to make a “clone” of the original file. At the timethe clone is created, both the clone and the original share the same setof pointers. However, to users they are two completely independentfiles. If a user modifies a block, call it block A, in the original file(which is shared by the clone), the clone will be modified at the sametime. Assuming copy-on-write is being used, the original file will get anew block, block A′, and the clone will get another new block, block A″,through two simultaneous copy-on-write operations.

Yet another advantage of the above-described technique is that a filesystem with shared data blocks can be easily converted to a file systemwithout shared blocks, if desired. For example, when such an operationis desired, any data blocks whose REFCOUNTs are greater than one aresimply copied out to new locations, the RECOUNTs of those data blocksare then each decremented by one, and block pointers are adjusted asnecessary to point to the new instances of those blocks.

Still another advantage is that the above-described technique allows forefficient replication. When replicating a file system or a portionthereof, for example, shared blocks only need to be sent from the sourceto the destination once, thus making replication morebandwidth-efficient. In addition, the replicated file system will useless space than it would otherwise, just as with the original volumes.

FIG. 8 illustrates elements of the de-duplication module 39, accordingto certain embodiments of the invention. The elements include ade-duplication engine 81, a gatherer module 82, a fingerprint manager83, a fingerprint handler 84 and a block sharing engine 85. Thefingerprints database 43 stores the fingerprints of all data blocks thathave been written to the storage subsystem 4, as noted above. In certainembodiments, each fingerprint is a checksum, such as an MD5 checksum.Each block has a separate entry in the fingerprints database 43. Eachsuch entry includes the fingerprint of the block, the inode number ofthe file to which the block belongs, and the FBN of the block.

The fingerprint handler 84 is responsible for computing the fingerprintsof data blocks. The gatherer module 82 is responsible for identifyingnew data blocks and for triggering the fingerprint handler 84 to computefingerprints of the new data blocks and return them to the gatherermodule 82. The fingerprint manager 83 receives the fingerprints of thenew data blocks from the gatherer module 82 and updates the fingerprintsdatabase 43 to include entries for those data blocks. The fingerprintmanager 83 is also responsible for identifying potentially duplicatedata blocks, by finding entries with matching fingerprints in thefingerprints database 43. The block sharing engine 85 is responsible forcomparing potentially duplicate data blocks identified by thefingerprint manager 83 to identify actual duplicate data blocks, and forcalling functions of the file system 31 when appropriate to eliminateduplicate data blocks and implement block sharing. For performancereasons, multiple block share operations may be ongoing at any giventime. The de-duplication engine 81 schedules and triggers operations ofthe other modules. In particular, the de-duplication engine 81 triggersoperation of the gatherer module 82, which may be done according to apre-specified schedule, timing algorithm, or in response to a manualinput.

According to certain embodiments of the invention, at any particularpoint in time a block will be in one of the following states: free,in-use, fingerprinted, shared, and zombie. A free block is a block thatis not being used (not allocated). An in-use block is a block that isbeing used and has not yet been processed by the de-duplicationoperation. A fingerprinted block is a block that has been processed bythe de-duplication operation, and for which an entry has been added intothe fingerprints database to track the block. A shared block is a blockthat has become shared and for which one or more duplicates of thisblock have been identified and eliminated. A zombie is a block that wasshared but now is no longer used by any files, but the block has not yetbeen freed. FIG. 9 illustrates how a block can transition through thevarious states in response to various events.

FIG. 10 shows a process performed by the de-duplication module 39 when ablock is written to disk. In response to a request to write a block at1001, the fingerprint handler 84 computes a fingerprint for the block at1003. The fingerprint is passed to the fingerprint manager 83, whichwrites an entry for the block into the fingerprints database 43 at 1004including the fingerprint, the FBN, the inode number of the block, andother relevant context information that is specific to this block, suchas the value of a consistency point counter at the time the block waswritten to disk. These operations 1003 and 1004 are performedconcurrently with the operation of writing 1002 the blocks to thestorage subsystem 4. In alternative embodiments, however, computing thefingerprint (1003) and writing the fingerprint to the fingerprintsdatabase 43 may not be performed concurrently with writing the block todisk, although doing so is believed to be more efficient.

As noted above, the information saved in the fingerprints database 43for each block includes context information, such as the value of aconsistency point counter at the time the block was written to disk.This context information can be used to detect and delete “stale”fingerprints from the fingerprints database 43. Stale fingerprints arefingerprints that corresponds to blocks that have been deleted oroverwritten. Entries with higher consistency point counter values aremore recent than entries with lower consistency point counter values.Complementary to this functionality, information on the deleted filesand/or blocks in the deletion code path is also logged and used to cleanup stale entries.

FIG. 11 illustrates the process of eliminating duplicate data blocks. Incertain embodiments of the invention, the process of FIG. 11 isperformed only during idle time of the file server 2 (unlike the processof FIG. 10, which is performed during writes), to avoid consumingprocessing resources and thereby adversely impacting system performance.At 1101 the fingerprints database is sorted, by fingerprint. Sorting thefingerprints database is optional but allows faster identification ofduplicate blocks, since the entries for any duplicates will resideadjacent to each other in the fingerprints database after the sortoperation is complete. At 1102 the process determines from thefingerprints database whether there are any entries with identicalfingerprints. The blocks represented by any entries which have identicalfingerprints are considered to be potential duplicate blocks, ratherthan actual duplicates, since there is always a possibility that twonon-identical blocks could have the same fingerprint, regardless of thefingerprint scheme being used. If there are no entries with identicalfingerprints, the process ends. If there are any entries with identicalfingerprints, the process proceeds to 1103, in which the processcompares the potential duplicate blocks with each other to determine ifthey are in fact identical. In an alternative embodiment, operation 1103could be eliminated if an approximate verification of comparingfingerprints is deemed sufficient in determining that two blocks areidentical.

If the blocks are not identical (1104), the process proceeds to 1108,described below. If the blocks are identical, then at 1105 the processfrees the duplicate block or blocks so that only one instance remains ofeach unique block, and shares the remaining instance of the block to theextent possible. The process then updates the reference count file 41and the Active map 42 at 1106 to reflect the newly shared and freedblocks. At 1107 the process deletes the entries for any freed blocksfrom the fingerprints database 43. Following either 1107 or a negativeoutcome of 1102, the process determines whether the entire fingerprintsdatabase 43 has been examined. If the entire fingerprints database 43has not been examined, the process loops back to 1102 and continues asdescribed above, until the entire fingerprints database 43 has beenexamined.

Note that the process of FIG. 11 can be executed in separate stages, forperformance reasons. For example, the first stage can be determination1102 of whether any entries have identical fingerprints; the secondstage can be 1103 to 1106, to perform deduplication on all identifiedduplicate blocks. In a third stage, 1107 can be done to remove all staleentries in one pass. As such, operations within each stage can bereordered, if desired, to optimize performance.

In certain embodiments of the invention, sorting of the fingerprintsdatabase 43 (1101 in FIG. 11) is done in the following manner, asillustrated in FIG. 12. First, the fingerprints database is divided intosome number, N, of approximately equal-sized chunks 121. Each of the Nchunks 121 is then independently sorted by fingerprint value, using anyconventional sorting algorithm, such as Quicksort, for example. Thealgorithm then compares the fingerprints in the entries of the same rankin all of the N chunks 121 (e.g., the top entry in each of the N chunks121) and copies the entry which has the smallest fingerprint value fromamong those into the next available slot in the sorted output file 122.The output file 122 becomes the sorted fingerprints database 43 when thesorting operation is complete. This process is then repeated until allof the entries in the N sorted chunks 121 have been copied into theoutput file 122.

FIG. 13 illustrates in greater detail the operation of freeing a datablock, such as a duplicate block. At 1301 the process determines whetherthe SHARED flag is set for the file which contains the block to befreed. If the SHARED flag is not set (meaning that no blocks in the fileare shared), the process proceeds to 1304, in which the bitcorresponding to the block is cleared in the Active map 42. The processthen ends. If the SHARED flag is not set at 1301, then at 1302 theprocess decrements the REFCOUNT value for the block by one in thereference count file 41. After decrementing the REFCOUNT value, theprocess determines at 1303 whether the REFCOUNT value is zero. If theREFCOUNT value is zero (meaning that the block is no longer used), theprocess clears the corresponding bit in the Active map 42 and then ends.If the REFCOUNT value is determined to be non-zero at 1303, the processsimply ends.

In certain embodiments, the system also maintains a change log 44 (FIG.3) to identify blocks that are new or modified since the last time theprocess of FIG. 11 was executed. The change log 44 contains informationof the same type as the fingerprints database 43 (i.e., fingerprint ofthe block, inode number of the file to which the block belongs, and theFBN of the block), but only for new or modified blocks. From time totime, the system then re-executes the sorting process of FIG. 12 on boththe fingerprints database 43 and the change log 44, to merge the changelog 44 into the fingerprints database 43.

In alternative embodiments, rather than using the techniques of FIGS. 11and 12 to identify and eliminate duplicate data blocks, the system couldsimply from time to time scan the entire file system, compute thefingerprints of all data blocks, and eliminate duplicates at essentiallythe same time. However, the technique described above is believed to bemore efficient.

Thus, a method and apparatus for identifying and eliminating duplicatedata blocks and for sharing data blocks have been described. Note thatreferences throughout this specification to “one embodiment” or “anembodiment” means that a particular feature, structure or characteristicdescribed in connection with the embodiment is included in at least oneembodiment of the present invention. Therefore, it is emphasized andshould be appreciated that two or more references to “an embodiment” or“one embodiment” or “an alternative embodiment” in various portions ofthis specification are not necessarily all referring to the sameembodiment. Furthermore, the particular features, structures orcharacteristics being referred to may be combined as suitable in one ormore embodiments of the invention, as will be recognized by those ofordinary skill in the art.

Although the present invention has been described with reference tospecific exemplary embodiments, it will be recognized that the inventionis not limited to the embodiments described, but can be practiced withmodification and alteration within the spirit and scope of the appendedclaims. Accordingly, the specification and drawings are to be regardedin an illustrative sense rather than a restrictive sense.

1-30. (canceled)
 31. A method comprising: allocating a first data blockfor a first file in a hierarchical file system in a storage server;determining that the first data block and a second data block in thefile system are duplicates of each other; sharing the first data blockamong the first and second files in the file system in response to thedetermining that the first and second data blocks are duplicates of eachother; and eliminating the second data block from the file system toreduce data block duplication in the file system.
 32. The method ofclaim 31, wherein the file system performs copy-on-write for changes todata blocks.
 33. The method of claim 31, wherein determining that thefirst and second data blocks are duplicates of each other furthercomprises: maintaining a fingerprint for written data blocks in thefilesystem; and comparing data block fingerprints to detect duplicatedata blocks.
 34. The method of claim 33, wherein detecting identicalfingerprints for data blocks indicates a potential that data blocks areduplicates of each other, and further comprising: performing a blockcomparison of data blocks that have identical fingerprints.
 35. Themethod of claim 31, wherein sharing the first data block among the firstand second files comprises: referencing the first data block from boththe first and second files with pointers.
 36. The method of claim 35,further comprising: maintaining a reference count associated with thefirst data block indicating a number of active references to the firstdata block.
 37. The method of claim 36, further comprising reversing thesharing of the first data block, including: creating a copy of the firstdata block; decrementing the reference count associated with the firstdata block; and modifying the pointer of the second file to referencethe copy instead of the first data block.
 38. The method of claim 31,wherein the determining, sharing, and eliminating are performed by abackground process of the file system.
 39. The method of claim 31,further comprising: replicating at least a portion of the file system toa remote destination including replicating the first and second files,wherein the replicating includes copying the first data block to thedestination only once for both the first and second files.
 40. Themethod of claim 31, wherein the first data block is for a first file,and the second data block is for a second file different than the firstfile.
 41. An article of manufacture comprising a computer readablestorage medium having content stored thereon to provide instructions,which when executed cause a machine to perform operations including:allocating a first data block for a first file in a hierarchical filesystem in a storage server; determining that the first data block and asecond data block in the file system are duplicates of each other;sharing the first data block among the first and second files in thefile system in response to the determining that the first and seconddata blocks are duplicates of each other; and eliminating the seconddata block from the file system to reduce data block duplication in thefile system.
 42. The article of manufacture of claim 41, wherein theinstructions for determining that the first and second data blocks areduplicates of each other further comprises instructions for maintaininga fingerprint for written data blocks in the filesystem; and comparingdata block fingerprints to identify duplicate data blocks.
 43. Thearticle of manufacture of claim 42, wherein the instructions fordetecting identical fingerprints for data blocks indicates a potentialthat data blocks are duplicates of each other, and further comprisinginstructions for performing a block comparison of data blocks that haveidentical fingerprints.
 44. The article of manufacture of claim 41,wherein the instructions for sharing the first data block among thefirst and second files comprises instructions for referencing the firstdata block from both the first and second files with pointers.
 45. Thearticle of manufacture of claim 44, further comprising instructions formaintaining a reference count associated with the first data blockindicating a number of active references to the first data block.
 46. Afile server comprising: storage adapter hardware to couple to a storagesubsystem including one or more mass storage devices that store data; aprocessor device; an operating system configured for execution by theprocessor device including file system and a de-duplication module,wherein the de-duplication module is to determine that a first datablock allocated by the file system for a first file in the file system,and a second data block in the file system are duplicates of each other;share the first data block among the first and second files in the filesystem in response to the determining that the first and second datablocks are duplicates of each other; and mark the second data block forelimination from the file system to reduce data block duplication in thefile system.
 47. The file server of claim 46, wherein the de-duplicationmodule is further to maintain a fingerprint for written data blocks inthe filesystem; and detect duplication data blocks at least in part bycomparing data block fingerprints.
 48. The file server of claim 46,wherein sharing the first data block among the first and second filescomprises: referencing the first data block from both the first andsecond files with pointers; and maintaining a reference count associatedwith the first data block indicating a number of active references tothe first data block.
 49. The file server of claim 46, wherein thede-duplication module is further to replicate at least a portion of thefile system to a remote destination including replicating the first andsecond files, wherein the replicating includes copying the first datablock to the destination only once for both the first and second files.50. The file server of claim 46, wherein the file system is to create aclone file of a source file by generating pointers from the clone fileto shared data blocks pointed to by the source file, and increasing areference count associated with data blocks of the original file toindicate new active references from the clone file.